package cloudInformation.controller;

import cloudEntity.dto.SmartExaminationPerformanceDTO;
import cloudEntity.entity.SmartExaminationPerformanceEntity;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.user.SmartExaminationPerformanceVO;
import cloudInformation.annotate.AuthCheck;
import cloudInformation.mapper.SmartExaminationPerformanceMapper;
import cloudInformation.service.SmartExaminationPerformanceService;
import huang.cloudUserApi.AuthFeignClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: Smart School
 * @ClassName ExaminationPerformanceController
 * @description: 学生成绩控制器
 * @author: 陈智博
 * @create: 2025-04-15 09:41
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/examination")
@Tag(name = "考试成绩控制器")
public class ExaminationPerformanceController {

    @Autowired
    private AuthFeignClient authFeignClient;

    @Autowired
    private SmartExaminationPerformanceMapper smartExaminationPerformanceMapper;

    @Autowired
    private SmartExaminationPerformanceService smartExaminationPerformanceService;

    @Operation(summary = "根据UID获取用户的考试成绩")
    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
    public ResultUtils<List<SmartExaminationPerformanceVO>> getUserExaminationPerformanceScore() {
        String sysUserUid = authFeignClient.smartUser().getSysUserUid();
        return ResultUtils.success(smartExaminationPerformanceMapper.getUserExaminationScore(sysUserUid));
    }

    @Operation(summary = "新增学生成绩")
    @Parameter(name = "smartExaminationPerformanceDTO",description = "学生成绩DTO",required = true)
    @RequestMapping(value = "/add/student/score",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils addStudentScore(@RequestBody SmartExaminationPerformanceDTO smartExaminationPerformanceDTO)
    {
        Integer i = smartExaminationPerformanceMapper.insertUserExaminationScore(smartExaminationPerformanceDTO);
        if(i>0)
        {
            return ResultUtils.success("新增学生成绩成功!");
        }
        return ResultUtils.failed("新增学生成绩失败!");
    }

    @Operation(summary = "修改学生成绩")
    @RequestMapping(value = "/update/student/score",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils updateStudentScore(@RequestBody SmartExaminationPerformanceEntity smartExaminationPerformanceEntity)
    {
        Integer i = smartExaminationPerformanceService.updateSmartExaminationPerformance(smartExaminationPerformanceEntity);
        if(i>0)
        {
            return ResultUtils.success("修改学生成绩成功!");
        }
        return ResultUtils.failed("修改学生成绩失败!");
    }



}
